<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2018/5/3
 * Time: 9:17
 */

namespace app\index\controller;


use app\common\controller\HomeBase;
use app\common\model\Article as ArticleModel;
use app\common\model\Banner as BannerModel;
use app\common\model\SkillType;
use app\common\model\Systems as SystemsModel;
use app\common\model\User;
use think\Session;

class Index extends HomeBase{

    protected $banner_model;
    protected $article_model;
    protected $systems_model;

    protected function _initialize()
    {
        parent::_initialize();
        $this->banner_model = new BannerModel();
        $this->article_model = new ArticleModel();
        $this->systems_model = new SystemsModel();
    }
    /**
     * 首页轮播
     */
    public function index()
    {
        $banner = $this->banner_model->getBanner();
        $this->assign('banner',$banner);
        return $this->fetch();
    }

    /**
     * 公司简介
     */
    public function about()
    {
        $detail =  $this->article_model->getdetail();
        $this->assign('detail', $detail);
        return $this->fetch();
    }
    /**
     *联系我们
     */
    public function concat()
    {
        $detail = $this->systems_model->concat();
        $this->assign('detail', $detail);
        return $this->fetch();
    }
    /**
     * 新闻动态页面列表
     */
    public function news()
    {
        //新闻动态页面  上面的轮播图   取最新5条新闻的图片作为轮播
        $newsbanner = $this->article_model->newsbanner();
        //新闻动态列表
        $newslist = $this->article_model->newslist();
        $this->assign('newsbanner', $newsbanner);
        $this->assign('newslist', $newslist);
        return $this->fetch();
    }
    /**
     * 新闻详情
     */
    public function newsdetial()
    {
        $id = input('id');
        $detail = $this->article_model->getNewsDetail($id);
        //获取当前新闻的上一篇
        $lastone =  $this->article_model->lastone($id);
        //获取当前新闻的下一篇
        $nextone = $this->article_model->nextone($id);
        $this->assign('detail', $detail);
        $this->assign('lastone', $lastone);
        $this->assign('nextone', $nextone);
        return $this->fetch();
    }

    /**
     * 众包首页 优质开发商推荐
     */
    public function highQualityUser()
    {
        $data =  User::getGoodUser();
        if ($data) {
            return json(['code' =>200,  'msg' => $data]);
        } else {
            return json(['code' => 301, 'msg' => '暂无数据']);
        }
    }

    /**
     * 首页 选择应用类型前十名类型接口
     */
    public function getProjectType()
    {
        $data = SkillType::getTopTenType();
        if ($data) {
            return json(['code' =>200,  'msg' => $data]);
        } else {
            return json(['code' => 301, 'msg' => '暂无数据']);
        }
    }


}